package kyssion.leetcode.num201_250;

import java.util.ArrayList;
import java.util.List;

public class code228_汇总区间 {
    public static void main(String[] args) {
        List<String> ll
                = new code228_汇总区间().summaryRanges(
                new int[]{
                        0,2,3,4,6,8,9
                }
        );
        System.out.println();
    }

    public List<String> summaryRanges(int[] nums) {
        if (nums.length == 0) {
            return new ArrayList<>();
        }
        List<String> list = new ArrayList<>();
        if (nums.length == 1) {
            list.add("" + nums[0]);
            return list;
        }
        int start = 0;
        int end = 1;
        while (end < nums.length) {
            if (nums[end] != nums[end - 1] + 1) {
                if (start == end - 1) {
                    list.add("" + nums[start]);
                } else {
                    list.add("" + nums[start] + "->" + nums[end-1]);
                }
                start = end;
            }
            end++;
        }
        if (start == end - 1) {
            list.add("" + nums[start]);
        } else {
            list.add("" + nums[start] + "->" + nums[end-1]);
        }
        return list;
    }

}
